{
 "cells": [
  {
   "cell_type": "markdown",
   "source": [
    "# numba支持测试\n",
    "参考 http://numba.pydata.org/numba-doc/dev/reference/numpysupported.html\n",
    "1. numba擅长加速numpy.ndarray, 因为这是array，不是linkedlist，内存布局良好，而且有很多可以用于编译的信息。\n",
    "2. numba对numpy的支持有几个方面\n",
    "    - Universal functions (ufunc) （是一个类型）\n",
    "        - a function that operates on ndarrays in an element-by-element fashion。 不过据此可以生成类型转换和广播\n",
    "        - 输入固定长度的输入，提供固定长度的输出\n",
    "        - 这个类有成员函数和属性。\n",
    "        - numpy有60种ufunc，可以有accumulate reduce\n",
    "    - indexing 很快，可以编译为直接内存访问\n",
    "    - 可以形成ufunc\n",
    "3. 明确不支持的：任何Python普通对象的出现\n",
    "4."
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%% md\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[ 0  1  3  6 10]\n"
     ]
    },
    {
     "data": {
      "text/plain": "0"
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import numba.typed.typeddict\n",
    "import numpy as np\n",
    "# ufunc\n",
    "print(np.add.accumulate(np.arange(5)))\n",
    "np.multiply.reduce(np.arange(5))"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "outputs": [],
   "source": [
    "from numba import *\n"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "markdown",
   "source": [
    "## 首先Python原生语法\n",
    "参考 http://numba.pydata.org/numba-doc/dev/reference/pysupported.html"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%% md\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "outputs": [
    {
     "ename": "TypingError",
     "evalue": "Failed in nopython mode pipeline (step: nopython frontend)\n\u001B[1mUntyped global name '类':\u001B[0m \u001B[1m\u001B[1mCannot determine Numba type of <class 'type'>\u001B[0m\n\u001B[1m\nFile \"C:\\Users\\YeCanming\\AppData\\Local\\Temp\\ipykernel_16840\\1294352717.py\", line 9:\u001B[0m\n\u001B[1m    def 很好(a, b):\n        <source elided>\n        # return a+b+类.静态变量  # 也不行\n\u001B[1m        return a+b+类.udlr_luruldrd  # 也不行\n\u001B[0m        \u001B[1m^\u001B[0m\u001B[0m\n\u001B[0m",
     "output_type": "error",
     "traceback": [
      "\u001B[1;31m---------------------------------------------------------------------------\u001B[0m",
      "\u001B[1;31mTypingError\u001B[0m                               Traceback (most recent call last)",
      "Input \u001B[1;32mIn [16]\u001B[0m, in \u001B[0;36m<cell line: 15>\u001B[1;34m()\u001B[0m\n\u001B[0;32m     11\u001B[0m     \u001B[38;5;129m@staticmethod\u001B[39m\n\u001B[0;32m     12\u001B[0m     \u001B[38;5;129m@njit\u001B[39m\n\u001B[0;32m     13\u001B[0m     \u001B[38;5;28;01mdef\u001B[39;00m \u001B[38;5;21m哈哈\u001B[39m(a, b):\n\u001B[0;32m     14\u001B[0m         \u001B[38;5;28;01mreturn\u001B[39;00m a\u001B[38;5;241m+\u001B[39mb\n\u001B[1;32m---> 15\u001B[0m \u001B[43m类\u001B[49m\u001B[38;5;241;43m.\u001B[39;49m\u001B[43m很好\u001B[49m\u001B[43m(\u001B[49m\u001B[38;5;241;43m1\u001B[39;49m\u001B[43m,\u001B[49m\u001B[38;5;241;43m2\u001B[39;49m\u001B[43m)\u001B[49m\n\u001B[0;32m     16\u001B[0m 类\u001B[38;5;241m.\u001B[39m哈哈(\u001B[38;5;241m1\u001B[39m,\u001B[38;5;241m2\u001B[39m)\n",
      "File \u001B[1;32mF:\\Programs\\Python\\lib\\site-packages\\numba\\core\\dispatcher.py:468\u001B[0m, in \u001B[0;36m_DispatcherBase._compile_for_args\u001B[1;34m(self, *args, **kws)\u001B[0m\n\u001B[0;32m    464\u001B[0m         msg \u001B[38;5;241m=\u001B[39m (\u001B[38;5;124mf\u001B[39m\u001B[38;5;124m\"\u001B[39m\u001B[38;5;132;01m{\u001B[39;00m\u001B[38;5;28mstr\u001B[39m(e)\u001B[38;5;241m.\u001B[39mrstrip()\u001B[38;5;132;01m}\u001B[39;00m\u001B[38;5;124m \u001B[39m\u001B[38;5;130;01m\\n\u001B[39;00m\u001B[38;5;130;01m\\n\u001B[39;00m\u001B[38;5;124mThis error may have been caused \u001B[39m\u001B[38;5;124m\"\u001B[39m\n\u001B[0;32m    465\u001B[0m                \u001B[38;5;124mf\u001B[39m\u001B[38;5;124m\"\u001B[39m\u001B[38;5;124mby the following argument(s):\u001B[39m\u001B[38;5;130;01m\\n\u001B[39;00m\u001B[38;5;132;01m{\u001B[39;00margs_str\u001B[38;5;132;01m}\u001B[39;00m\u001B[38;5;130;01m\\n\u001B[39;00m\u001B[38;5;124m\"\u001B[39m)\n\u001B[0;32m    466\u001B[0m         e\u001B[38;5;241m.\u001B[39mpatch_message(msg)\n\u001B[1;32m--> 468\u001B[0m     \u001B[43merror_rewrite\u001B[49m\u001B[43m(\u001B[49m\u001B[43me\u001B[49m\u001B[43m,\u001B[49m\u001B[43m \u001B[49m\u001B[38;5;124;43m'\u001B[39;49m\u001B[38;5;124;43mtyping\u001B[39;49m\u001B[38;5;124;43m'\u001B[39;49m\u001B[43m)\u001B[49m\n\u001B[0;32m    469\u001B[0m \u001B[38;5;28;01mexcept\u001B[39;00m errors\u001B[38;5;241m.\u001B[39mUnsupportedError \u001B[38;5;28;01mas\u001B[39;00m e:\n\u001B[0;32m    470\u001B[0m     \u001B[38;5;66;03m# Something unsupported is present in the user code, add help info\u001B[39;00m\n\u001B[0;32m    471\u001B[0m     error_rewrite(e, \u001B[38;5;124m'\u001B[39m\u001B[38;5;124munsupported_error\u001B[39m\u001B[38;5;124m'\u001B[39m)\n",
      "File \u001B[1;32mF:\\Programs\\Python\\lib\\site-packages\\numba\\core\\dispatcher.py:409\u001B[0m, in \u001B[0;36m_DispatcherBase._compile_for_args.<locals>.error_rewrite\u001B[1;34m(e, issue_type)\u001B[0m\n\u001B[0;32m    407\u001B[0m     \u001B[38;5;28;01mraise\u001B[39;00m e\n\u001B[0;32m    408\u001B[0m \u001B[38;5;28;01melse\u001B[39;00m:\n\u001B[1;32m--> 409\u001B[0m     \u001B[38;5;28;01mraise\u001B[39;00m e\u001B[38;5;241m.\u001B[39mwith_traceback(\u001B[38;5;28;01mNone\u001B[39;00m)\n",
      "\u001B[1;31mTypingError\u001B[0m: Failed in nopython mode pipeline (step: nopython frontend)\n\u001B[1mUntyped global name '类':\u001B[0m \u001B[1m\u001B[1mCannot determine Numba type of <class 'type'>\u001B[0m\n\u001B[1m\nFile \"C:\\Users\\YeCanming\\AppData\\Local\\Temp\\ipykernel_16840\\1294352717.py\", line 9:\u001B[0m\n\u001B[1m    def 很好(a, b):\n        <source elided>\n        # return a+b+类.静态变量  # 也不行\n\u001B[1m        return a+b+类.udlr_luruldrd  # 也不行\n\u001B[0m        \u001B[1m^\u001B[0m\u001B[0m\n\u001B[0m"
     ]
    }
   ],
   "source": [
    "class 类:\n",
    "    静态变量 = [1]\n",
    "    udlr_luruldrd = np.array([[-1, 0], [1, 0], [0, -1], [0, 1], [-1, -1], [-1, 1], [1, -1], [1, 1]])\n",
    "    @staticmethod\n",
    "    @njit\n",
    "    def 很好(a, b):\n",
    "        # print(类.静态变量) # 不行\n",
    "        # return a+b+类.静态变量  # 也不行\n",
    "        # return a+b+类.udlr_luruldrd  # 也不行\n",
    "        print(1)\n",
    "    @staticmethod\n",
    "    @njit\n",
    "    def 哈哈(a, b):\n",
    "        return a+b\n",
    "类.很好(1,2)\n",
    "类.哈哈(1,2)"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1\n"
     ]
    }
   ],
   "source": [
    "# 全局函数\n",
    "@njit\n",
    "def a():\n",
    "    # b = []\n",
    "    # print(len(b))  # 空列表不行\n",
    "    b = [1]\n",
    "    print(len(b))  # 空列表不行\n",
    "a()"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "outputs": [
    {
     "data": {
      "text/plain": "1"
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "@njit\n",
    "def test2():\n",
    "    x = [1, 2, 3]\n",
    "    # return sum(x) # ok\n",
    "    # return map(a, x) # not ok\n",
    "    return min(x) # ok\n",
    "test2()"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "outputs": [
    {
     "data": {
      "text/plain": "(2, 2)"
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "@njit\n",
    "def test_tuple():\n",
    "    x = (1,2)\n",
    "    # y = tuple([1,2]) # 不支持\n",
    "    y = (1,2) # 支持\n",
    "    return x[0] + y[0], x[1]\n",
    "test_tuple()\n",
    "# note: 不要随便做类型转换"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "outputs": [
    {
     "data": {
      "text/plain": "4"
     },
     "execution_count": 21,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "@njit\n",
    "def test_call(a, b):\n",
    "    a, b = test_tuple()\n",
    "    return a+b\n",
    "test_call(1,2)"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 44,
   "outputs": [
    {
     "data": {
      "text/plain": "0"
     },
     "execution_count": 44,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "@njit\n",
    "def test_argwhere():\n",
    "    def t(x):\n",
    "        return x%2==0\n",
    "    a = np.arange(100).reshape((10,10))\n",
    "    print(a)\n",
    "    # return np.argwhere(a<=20&t(a))\n",
    "    return np.argwhere((lambda x:x<=20 & t(x))(a))\n",
    "    # return np.argwhere(t(a))\n",
    "    # return np.argwhere(a<=20)\n",
    "\n",
    "\n",
    "# print(test_argwhere())\n",
    "a = np.arange(100).reshape((10,10))\n",
    "(a<=20) & True\n",
    "a<=20 & True\n",
    "20&True    # 震惊世界的符号优先级bug"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 54,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[ 0  1  2  3  4  5  6  7  8  9]\n",
      " [10 11 12 13 14 15 16 17 18 19]\n",
      " [20 21 22 23 24 25 26 27 28 29]\n",
      " [30 31 32 33 34 35 36 37 38 39]\n",
      " [40 41 42 43 44 45 46 47 48 49]\n",
      " [50 51 52 53 54 55 56 57 58 59]\n",
      " [60 61 62 63 64 65 66 67 68 69]\n",
      " [70 71 72 73 74 75 76 77 78 79]\n",
      " [80 81 82 83 84 85 86 87 88 89]\n",
      " [90 91 92 93 94 95 96 97 98 99]]\n",
      "22\n",
      "22\n",
      "22\n",
      "22\n"
     ]
    }
   ],
   "source": [
    "@njit(inline='always')\n",
    "def index1(x,y):\n",
    "    return x, y\n",
    "@njit(inline='always')\n",
    "def index2(x):\n",
    "    return x[0], x[1]\n",
    "@njit\n",
    "def test_indexing():\n",
    "    x = np.arange(100).reshape(10, 10)\n",
    "    print(x)\n",
    "    print(x[2][2])\n",
    "    print(x[index2([2,2])])\n",
    "    print(x[index1(2,2)])\n",
    "    print(x[2,2])\n",
    "test_indexing()"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 56,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[ 0  1  2  3  4  5  6  7]\n",
      " [ 8  9 10 11 12 13 14 15]\n",
      " [16 17 18 19 20 21 22 23]\n",
      " [24 25 26 27 28 29 30 31]\n",
      " [32 33 34 35 36 37 38 39]\n",
      " [40 41 42 43 44 45 46 47]\n",
      " [48 49 50 51 52 53 54 55]\n",
      " [56 57 58 59 60 61 62 63]]\n"
     ]
    }
   ],
   "source": [
    "size = 8\n",
    "@njit\n",
    "def test_global():\n",
    "    print(np.arange(size**2).reshape(size, size))\n",
    "test_global()"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 59,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[-1  0]\n",
      "[-1  3]\n",
      "[1 0]\n",
      "[1 3]\n",
      "[ 0 -1]\n",
      "[0 2]\n",
      "[0 1]\n",
      "[0 4]\n",
      "[-1 -1]\n",
      "[-1  2]\n",
      "[-1  1]\n",
      "[-1  4]\n",
      "[ 1 -1]\n",
      "[1 2]\n",
      "[1 1]\n",
      "[1 4]\n"
     ]
    }
   ],
   "source": [
    "udlr_luruldrd = np.array([[-1, 0], [1, 0], [0, -1], [0, 1], [-1, -1], [-1, 1], [1, -1], [1, 1]])\n",
    "@njit\n",
    "def test_add():\n",
    "    index = np.argwhere(np.arange(10).reshape(2,5)==3)[0]\n",
    "    for i in udlr_luruldrd:\n",
    "        print(i)\n",
    "        print(i+index)\n",
    "test_add()"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 60,
   "outputs": [
    {
     "data": {
      "text/plain": "['2C',\n '2D',\n '2H',\n '2S',\n '3C',\n '3D',\n '3H',\n '3S',\n '4C',\n '4D',\n '4H',\n '4S',\n '5C',\n '5D',\n '5H',\n '5S',\n '6C',\n '6D',\n '6H',\n '6S',\n '7C',\n '7D',\n '7H',\n '7S',\n '8C',\n '8D',\n '8H',\n '8S',\n '9C',\n '9D',\n '9H',\n '9S',\n 'TC',\n 'TD',\n 'TH',\n 'TS',\n 'JC',\n 'JD',\n 'JH',\n 'JS',\n 'QC',\n 'QD',\n 'QH',\n 'QS',\n 'KC',\n 'KD',\n 'KH',\n 'KS',\n 'AC',\n 'AD',\n 'AH',\n 'AS']"
     },
     "execution_count": 60,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "from numba import jit\n",
    "@jit()\n",
    "def create_card_deck():\n",
    "    values = \"23456789TJQKA\"\n",
    "    suites = \"CDHS\"\n",
    "    Deck = []\n",
    "    for x in values:\n",
    "        for y in suites:\n",
    "            Deck.append(x + y)\n",
    "    return Deck\n",
    "\n",
    "create_card_deck()"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 63,
   "outputs": [
    {
     "ename": "TypingError",
     "evalue": "Failed in nopython mode pipeline (step: nopython frontend)\n\u001B[1m\u001B[1mCannot unify float64 and UniTuple(int64 x 2) for 'max_value.2', defined at C:\\Users\\YeCanming\\AppData\\Local\\Temp\\ipykernel_16840\\2971131936.py (5)\n\u001B[1m\nFile \"C:\\Users\\YeCanming\\AppData\\Local\\Temp\\ipykernel_16840\\2971131936.py\", line 5:\u001B[0m\n\u001B[1mdef decide():\n    <source elided>\n    max_value, argmax = -np.inf, None\n\u001B[1m    for action in candidates:\n\u001B[0m    \u001B[1m^\u001B[0m\u001B[0m\n\u001B[0m\n\u001B[0m\u001B[1mDuring: typing of assignment at C:\\Users\\YeCanming\\AppData\\Local\\Temp\\ipykernel_16840\\2971131936.py (5)\u001B[0m\n\u001B[1m\nFile \"C:\\Users\\YeCanming\\AppData\\Local\\Temp\\ipykernel_16840\\2971131936.py\", line 5:\u001B[0m\n\u001B[1mdef decide():\n    <source elided>\n    max_value, argmax = -np.inf, None\n\u001B[1m    for action in candidates:\n\u001B[0m    \u001B[1m^\u001B[0m\u001B[0m\n",
     "output_type": "error",
     "traceback": [
      "\u001B[1;31m---------------------------------------------------------------------------\u001B[0m",
      "\u001B[1;31mTypingError\u001B[0m                               Traceback (most recent call last)",
      "Input \u001B[1;32mIn [63]\u001B[0m, in \u001B[0;36m<cell line: 9>\u001B[1;34m()\u001B[0m\n\u001B[0;32m      7\u001B[0m             max_value, argmax \u001B[38;5;241m=\u001B[39m candidates[\u001B[38;5;241m1\u001B[39m], candidates[\u001B[38;5;241m0\u001B[39m]\n\u001B[0;32m      8\u001B[0m     \u001B[38;5;28;01mreturn\u001B[39;00m max_value, argmax\n\u001B[1;32m----> 9\u001B[0m \u001B[43mdecide\u001B[49m\u001B[43m(\u001B[49m\u001B[43m)\u001B[49m\n",
      "File \u001B[1;32mF:\\Programs\\Python\\lib\\site-packages\\numba\\core\\dispatcher.py:468\u001B[0m, in \u001B[0;36m_DispatcherBase._compile_for_args\u001B[1;34m(self, *args, **kws)\u001B[0m\n\u001B[0;32m    464\u001B[0m         msg \u001B[38;5;241m=\u001B[39m (\u001B[38;5;124mf\u001B[39m\u001B[38;5;124m\"\u001B[39m\u001B[38;5;132;01m{\u001B[39;00m\u001B[38;5;28mstr\u001B[39m(e)\u001B[38;5;241m.\u001B[39mrstrip()\u001B[38;5;132;01m}\u001B[39;00m\u001B[38;5;124m \u001B[39m\u001B[38;5;130;01m\\n\u001B[39;00m\u001B[38;5;130;01m\\n\u001B[39;00m\u001B[38;5;124mThis error may have been caused \u001B[39m\u001B[38;5;124m\"\u001B[39m\n\u001B[0;32m    465\u001B[0m                \u001B[38;5;124mf\u001B[39m\u001B[38;5;124m\"\u001B[39m\u001B[38;5;124mby the following argument(s):\u001B[39m\u001B[38;5;130;01m\\n\u001B[39;00m\u001B[38;5;132;01m{\u001B[39;00margs_str\u001B[38;5;132;01m}\u001B[39;00m\u001B[38;5;130;01m\\n\u001B[39;00m\u001B[38;5;124m\"\u001B[39m)\n\u001B[0;32m    466\u001B[0m         e\u001B[38;5;241m.\u001B[39mpatch_message(msg)\n\u001B[1;32m--> 468\u001B[0m     \u001B[43merror_rewrite\u001B[49m\u001B[43m(\u001B[49m\u001B[43me\u001B[49m\u001B[43m,\u001B[49m\u001B[43m \u001B[49m\u001B[38;5;124;43m'\u001B[39;49m\u001B[38;5;124;43mtyping\u001B[39;49m\u001B[38;5;124;43m'\u001B[39;49m\u001B[43m)\u001B[49m\n\u001B[0;32m    469\u001B[0m \u001B[38;5;28;01mexcept\u001B[39;00m errors\u001B[38;5;241m.\u001B[39mUnsupportedError \u001B[38;5;28;01mas\u001B[39;00m e:\n\u001B[0;32m    470\u001B[0m     \u001B[38;5;66;03m# Something unsupported is present in the user code, add help info\u001B[39;00m\n\u001B[0;32m    471\u001B[0m     error_rewrite(e, \u001B[38;5;124m'\u001B[39m\u001B[38;5;124munsupported_error\u001B[39m\u001B[38;5;124m'\u001B[39m)\n",
      "File \u001B[1;32mF:\\Programs\\Python\\lib\\site-packages\\numba\\core\\dispatcher.py:409\u001B[0m, in \u001B[0;36m_DispatcherBase._compile_for_args.<locals>.error_rewrite\u001B[1;34m(e, issue_type)\u001B[0m\n\u001B[0;32m    407\u001B[0m     \u001B[38;5;28;01mraise\u001B[39;00m e\n\u001B[0;32m    408\u001B[0m \u001B[38;5;28;01melse\u001B[39;00m:\n\u001B[1;32m--> 409\u001B[0m     \u001B[38;5;28;01mraise\u001B[39;00m e\u001B[38;5;241m.\u001B[39mwith_traceback(\u001B[38;5;28;01mNone\u001B[39;00m)\n",
      "\u001B[1;31mTypingError\u001B[0m: Failed in nopython mode pipeline (step: nopython frontend)\n\u001B[1m\u001B[1mCannot unify float64 and UniTuple(int64 x 2) for 'max_value.2', defined at C:\\Users\\YeCanming\\AppData\\Local\\Temp\\ipykernel_16840\\2971131936.py (5)\n\u001B[1m\nFile \"C:\\Users\\YeCanming\\AppData\\Local\\Temp\\ipykernel_16840\\2971131936.py\", line 5:\u001B[0m\n\u001B[1mdef decide():\n    <source elided>\n    max_value, argmax = -np.inf, None\n\u001B[1m    for action in candidates:\n\u001B[0m    \u001B[1m^\u001B[0m\u001B[0m\n\u001B[0m\n\u001B[0m\u001B[1mDuring: typing of assignment at C:\\Users\\YeCanming\\AppData\\Local\\Temp\\ipykernel_16840\\2971131936.py (5)\u001B[0m\n\u001B[1m\nFile \"C:\\Users\\YeCanming\\AppData\\Local\\Temp\\ipykernel_16840\\2971131936.py\", line 5:\u001B[0m\n\u001B[1mdef decide():\n    <source elided>\n    max_value, argmax = -np.inf, None\n\u001B[1m    for action in candidates:\n\u001B[0m    \u001B[1m^\u001B[0m\u001B[0m\n"
     ]
    }
   ],
   "source": [
    "@njit\n",
    "def decide():\n",
    "    candidates = [(1,2), (3,4)]\n",
    "    max_value, argmax = -np.inf, None\n",
    "    for action in candidates:\n",
    "        if action[0]>max_value:\n",
    "            max_value, argmax = candidates[1], candidates[0]\n",
    "    return max_value, argmax\n",
    "decide()"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "outputs": [
    {
     "ename": "TypingError",
     "evalue": "Failed in nopython mode pipeline (step: nopython frontend)\n\u001B[1m\u001B[1mUnknown attribute 'tolist' of type array(float64, 1d, C)\n\u001B[1m\nFile \"C:\\Users\\Administrator\\AppData\\Local\\Temp\\ipykernel_1144\\3898525276.py\", line 15:\u001B[0m\n\u001B[1mdef test_vectorize(x):\n    <source elided>\n        d[a] = values[i]\n\u001B[1m    l = x.tolist()\n\u001B[0m    \u001B[1m^\u001B[0m\u001B[0m\n\u001B[0m\n\u001B[0m\u001B[1mDuring: typing of get attribute at C:\\Users\\Administrator\\AppData\\Local\\Temp\\ipykernel_1144\\3898525276.py (15)\u001B[0m\n\u001B[1m\nFile \"C:\\Users\\Administrator\\AppData\\Local\\Temp\\ipykernel_1144\\3898525276.py\", line 15:\u001B[0m\n\u001B[1mdef test_vectorize(x):\n    <source elided>\n        d[a] = values[i]\n\u001B[1m    l = x.tolist()\n\u001B[0m    \u001B[1m^\u001B[0m\u001B[0m\n",
     "output_type": "error",
     "traceback": [
      "\u001B[1;31m---------------------------------------------------------------------------\u001B[0m",
      "\u001B[1;31mTypingError\u001B[0m                               Traceback (most recent call last)",
      "Input \u001B[1;32mIn [30]\u001B[0m, in \u001B[0;36m<cell line: 20>\u001B[1;34m()\u001B[0m\n\u001B[0;32m     17\u001B[0m     \u001B[38;5;28mprint\u001B[39m(l[\u001B[38;5;241m0\u001B[39m:\u001B[38;5;241m100\u001B[39m])\n\u001B[0;32m     19\u001B[0m x \u001B[38;5;241m=\u001B[39m np\u001B[38;5;241m.\u001B[39marange(\u001B[38;5;241m1e7\u001B[39m)\n\u001B[1;32m---> 20\u001B[0m \u001B[43mtest_vectorize\u001B[49m\u001B[43m(\u001B[49m\u001B[43mx\u001B[49m\u001B[43m)\u001B[49m\n",
      "File \u001B[1;32mC:\\ProgramData\\Anaconda3\\lib\\site-packages\\numba\\core\\dispatcher.py:468\u001B[0m, in \u001B[0;36m_DispatcherBase._compile_for_args\u001B[1;34m(self, *args, **kws)\u001B[0m\n\u001B[0;32m    464\u001B[0m         msg \u001B[38;5;241m=\u001B[39m (\u001B[38;5;124mf\u001B[39m\u001B[38;5;124m\"\u001B[39m\u001B[38;5;132;01m{\u001B[39;00m\u001B[38;5;28mstr\u001B[39m(e)\u001B[38;5;241m.\u001B[39mrstrip()\u001B[38;5;132;01m}\u001B[39;00m\u001B[38;5;124m \u001B[39m\u001B[38;5;130;01m\\n\u001B[39;00m\u001B[38;5;130;01m\\n\u001B[39;00m\u001B[38;5;124mThis error may have been caused \u001B[39m\u001B[38;5;124m\"\u001B[39m\n\u001B[0;32m    465\u001B[0m                \u001B[38;5;124mf\u001B[39m\u001B[38;5;124m\"\u001B[39m\u001B[38;5;124mby the following argument(s):\u001B[39m\u001B[38;5;130;01m\\n\u001B[39;00m\u001B[38;5;132;01m{\u001B[39;00margs_str\u001B[38;5;132;01m}\u001B[39;00m\u001B[38;5;130;01m\\n\u001B[39;00m\u001B[38;5;124m\"\u001B[39m)\n\u001B[0;32m    466\u001B[0m         e\u001B[38;5;241m.\u001B[39mpatch_message(msg)\n\u001B[1;32m--> 468\u001B[0m     \u001B[43merror_rewrite\u001B[49m\u001B[43m(\u001B[49m\u001B[43me\u001B[49m\u001B[43m,\u001B[49m\u001B[43m \u001B[49m\u001B[38;5;124;43m'\u001B[39;49m\u001B[38;5;124;43mtyping\u001B[39;49m\u001B[38;5;124;43m'\u001B[39;49m\u001B[43m)\u001B[49m\n\u001B[0;32m    469\u001B[0m \u001B[38;5;28;01mexcept\u001B[39;00m errors\u001B[38;5;241m.\u001B[39mUnsupportedError \u001B[38;5;28;01mas\u001B[39;00m e:\n\u001B[0;32m    470\u001B[0m     \u001B[38;5;66;03m# Something unsupported is present in the user code, add help info\u001B[39;00m\n\u001B[0;32m    471\u001B[0m     error_rewrite(e, \u001B[38;5;124m'\u001B[39m\u001B[38;5;124munsupported_error\u001B[39m\u001B[38;5;124m'\u001B[39m)\n",
      "File \u001B[1;32mC:\\ProgramData\\Anaconda3\\lib\\site-packages\\numba\\core\\dispatcher.py:409\u001B[0m, in \u001B[0;36m_DispatcherBase._compile_for_args.<locals>.error_rewrite\u001B[1;34m(e, issue_type)\u001B[0m\n\u001B[0;32m    407\u001B[0m     \u001B[38;5;28;01mraise\u001B[39;00m e\n\u001B[0;32m    408\u001B[0m \u001B[38;5;28;01melse\u001B[39;00m:\n\u001B[1;32m--> 409\u001B[0m     \u001B[38;5;28;01mraise\u001B[39;00m e\u001B[38;5;241m.\u001B[39mwith_traceback(\u001B[38;5;28;01mNone\u001B[39;00m)\n",
      "\u001B[1;31mTypingError\u001B[0m: Failed in nopython mode pipeline (step: nopython frontend)\n\u001B[1m\u001B[1mUnknown attribute 'tolist' of type array(float64, 1d, C)\n\u001B[1m\nFile \"C:\\Users\\Administrator\\AppData\\Local\\Temp\\ipykernel_1144\\3898525276.py\", line 15:\u001B[0m\n\u001B[1mdef test_vectorize(x):\n    <source elided>\n        d[a] = values[i]\n\u001B[1m    l = x.tolist()\n\u001B[0m    \u001B[1m^\u001B[0m\u001B[0m\n\u001B[0m\n\u001B[0m\u001B[1mDuring: typing of get attribute at C:\\Users\\Administrator\\AppData\\Local\\Temp\\ipykernel_1144\\3898525276.py (15)\u001B[0m\n\u001B[1m\nFile \"C:\\Users\\Administrator\\AppData\\Local\\Temp\\ipykernel_1144\\3898525276.py\", line 15:\u001B[0m\n\u001B[1mdef test_vectorize(x):\n    <source elided>\n        d[a] = values[i]\n\u001B[1m    l = x.tolist()\n\u001B[0m    \u001B[1m^\u001B[0m\u001B[0m\n"
     ]
    }
   ],
   "source": [
    "@njit\n",
    "def updated(x, y):\n",
    "    return x+y\n",
    "@njit\n",
    "def evaluate(x):\n",
    "    return ((x-20)**2)\n",
    "@njit\n",
    "def test_vectorize(x):\n",
    "    y = 20\n",
    "    print(x+y)\n",
    "    values = evaluate(updated(x, y))\n",
    "    d = dict()\n",
    "    for i, a in enumerate(x):\n",
    "        d[a] = values[i]\n",
    "    l = x.tolist()\n",
    "    l.sort(key = d.get)\n",
    "    print(l[0:100])\n",
    "\n",
    "x = np.arange(1e7)\n",
    "test_vectorize(x)"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "outputs": [
    {
     "data": {
      "text/plain": "120"
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "def test_hash(x, a=None):\n",
    "    if a is None:\n",
    "        a = {}\n",
    "    return a[x]\n",
    "x = str(np.arange(100))\n",
    "# x = [(1,2), (3,4)]\n",
    "a = {x:120}\n",
    "test_hash(x, a)"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "outputs": [
    {
     "data": {
      "text/plain": "23"
     },
     "execution_count": 33,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "@njit\n",
    "def test_recur(x = 10):\n",
    "    if x<0:\n",
    "        return 1\n",
    "    return test_recur(x-1)+2\n",
    "test_recur(10)"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "outputs": [],
   "source": [
    "def test_sort(x):\n",
    "    x.sort()"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "20\n",
      "100\n",
      "1\n"
     ]
    },
    {
     "data": {
      "text/plain": "25"
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "from numba import njit\n",
    "# from typing import Dict\n",
    "from numba.typed import Dict\n",
    "# import\n",
    "@njit\n",
    "def test_hash_table(table:Dict):\n",
    "    print(table.get(1, 100))\n",
    "    print(table.get(12, 100))\n",
    "    print(len(table))\n",
    "    table[13] = 25\n",
    "    return table\n",
    "\n",
    "d = Dict()\n",
    "d[1] = 20\n",
    "test_hash_table(d)\n",
    "d[13]"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "outputs": [
    {
     "data": {
      "text/plain": "array([1., 2.])"
     },
     "execution_count": 26,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "from numba.typed import Dict\n",
    "from numba import types\n",
    "import numpy as np\n",
    "hash_table = Dict.empty(\n",
    "        key_type=types.unicode_type,\n",
    "        # value_type=types.List(types.UniTuple(types.int32,2))  # 表示行动的顺序\n",
    "        value_type=types.float64[:] # 表示行动的顺序\n",
    "    )\n",
    "hash_table['asdf'] = np.asarray([1,2],'f8')\n",
    "hash_table['asdf']"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "outputs": [
    {
     "ename": "TypingError",
     "evalue": "Failed in nopython mode pipeline (step: nopython frontend)\n\u001B[1m\u001B[1mNo implementation of function Function(<built-in function setitem>) found for signature:\n \n >>> setitem(DictType[unicode_type,ListType[UniTuple(int32 x 2)]]<iv=None>, Literal[str](asdf), list(UniTuple(int64 x 2))<iv=None>)\n \nThere are 16 candidate implementations:\n\u001B[1m      - Of which 14 did not match due to:\n      Overload of function 'setitem': File: <numerous>: Line N/A.\n        With argument(s): '(DictType[unicode_type,ListType[UniTuple(int32 x 2)]]<iv=None>, unicode_type, list(UniTuple(int64 x 2))<iv=None>)':\u001B[0m\n\u001B[1m       No match.\u001B[0m\n\u001B[1m      - Of which 1 did not match due to:\n      Overload in function 'impl_setitem': File: numba\\typed\\dictobject.py: Line 674.\n        With argument(s): '(DictType[unicode_type,ListType[UniTuple(int32 x 2)]]<iv=None>, unicode_type, list(UniTuple(int64 x 2))<iv=None>)':\u001B[0m\n\u001B[1m       Rejected as the implementation raised a specific error:\n         NumbaNotImplementedError: Failed in nopython mode pipeline (step: native lowering)\n       \u001B[1m\u001B[1mCannot cast list(UniTuple(int64 x 2))<iv=None> to ListType[UniTuple(int32 x 2)]: %\"inserted.parent.1\" = insertvalue {i8*, i8*} %\"inserted.meminfo.2\", i8* %\"arg.value.1\", 1\u001B[0m\n       \u001B[0m\u001B[1mDuring: lowering \"castedval = call $12load_global.4(value, $16load_deref.6, func=$12load_global.4, args=[Var(value, dictobject.py:683), Var($16load_deref.6, dictobject.py:684)], kws=(), vararg=None, target=None)\" at F:\\Programs\\Python\\lib\\site-packages\\numba\\typed\\dictobject.py (684)\u001B[0m\u001B[0m\n  raised from F:\\Programs\\Python\\lib\\site-packages\\numba\\core\\base.py:715\n\u001B[1m      - Of which 1 did not match due to:\n      Overload in function 'impl_setitem': File: numba\\typed\\dictobject.py: Line 674.\n        With argument(s): '(DictType[unicode_type,ListType[UniTuple(int32 x 2)]]<iv=None>, Literal[str](asdf), list(UniTuple(int64 x 2))<iv=None>)':\u001B[0m\n\u001B[1m       Rejected as the implementation raised a specific error:\n         NumbaNotImplementedError: Failed in nopython mode pipeline (step: native lowering)\n       \u001B[1m\u001B[1mCannot cast list(UniTuple(int64 x 2))<iv=None> to ListType[UniTuple(int32 x 2)]: %\"inserted.parent\" = insertvalue {i8*, i8*} %\"inserted.meminfo.1\", i8* %\"arg.value.1\", 1\u001B[0m\n       \u001B[0m\u001B[1mDuring: lowering \"castedval = call $12load_global.4(value, $16load_deref.6, func=$12load_global.4, args=[Var(value, dictobject.py:683), Var($16load_deref.6, dictobject.py:684)], kws=(), vararg=None, target=None)\" at F:\\Programs\\Python\\lib\\site-packages\\numba\\typed\\dictobject.py (684)\u001B[0m\u001B[0m\n  raised from F:\\Programs\\Python\\lib\\site-packages\\numba\\core\\base.py:715\n\u001B[0m\n\u001B[0m\u001B[1mDuring: typing of staticsetitem at C:\\Users\\YeCanming\\AppData\\Local\\Temp\\ipykernel_11780\\3448497629.py (11)\u001B[0m\n\u001B[1m\nFile \"C:\\Users\\YeCanming\\AppData\\Local\\Temp\\ipykernel_11780\\3448497629.py\", line 11:\u001B[0m\n\u001B[1mdef test_hash_table(hash_table):\n\u001B[1m    hash_table['asdf'] = [(1,2)]\n\u001B[0m    \u001B[1m^\u001B[0m\u001B[0m\n",
     "output_type": "error",
     "traceback": [
      "\u001B[1;31m---------------------------------------------------------------------------\u001B[0m",
      "\u001B[1;31mTypingError\u001B[0m                               Traceback (most recent call last)",
      "Input \u001B[1;32mIn [28]\u001B[0m, in \u001B[0;36m<cell line: 13>\u001B[1;34m()\u001B[0m\n\u001B[0;32m     11\u001B[0m     hash_table[\u001B[38;5;124m'\u001B[39m\u001B[38;5;124masdf\u001B[39m\u001B[38;5;124m'\u001B[39m] \u001B[38;5;241m=\u001B[39m [(\u001B[38;5;241m1\u001B[39m,\u001B[38;5;241m2\u001B[39m)]\n\u001B[0;32m     12\u001B[0m     \u001B[38;5;28mprint\u001B[39m(hash_table[\u001B[38;5;124m'\u001B[39m\u001B[38;5;124masdf\u001B[39m\u001B[38;5;124m'\u001B[39m])\n\u001B[1;32m---> 13\u001B[0m \u001B[43mtest_hash_table\u001B[49m\u001B[43m(\u001B[49m\u001B[43mhash_table\u001B[49m\u001B[43m)\u001B[49m\n",
      "File \u001B[1;32mF:\\Programs\\Python\\lib\\site-packages\\numba\\core\\dispatcher.py:468\u001B[0m, in \u001B[0;36m_DispatcherBase._compile_for_args\u001B[1;34m(self, *args, **kws)\u001B[0m\n\u001B[0;32m    464\u001B[0m         msg \u001B[38;5;241m=\u001B[39m (\u001B[38;5;124mf\u001B[39m\u001B[38;5;124m\"\u001B[39m\u001B[38;5;132;01m{\u001B[39;00m\u001B[38;5;28mstr\u001B[39m(e)\u001B[38;5;241m.\u001B[39mrstrip()\u001B[38;5;132;01m}\u001B[39;00m\u001B[38;5;124m \u001B[39m\u001B[38;5;130;01m\\n\u001B[39;00m\u001B[38;5;130;01m\\n\u001B[39;00m\u001B[38;5;124mThis error may have been caused \u001B[39m\u001B[38;5;124m\"\u001B[39m\n\u001B[0;32m    465\u001B[0m                \u001B[38;5;124mf\u001B[39m\u001B[38;5;124m\"\u001B[39m\u001B[38;5;124mby the following argument(s):\u001B[39m\u001B[38;5;130;01m\\n\u001B[39;00m\u001B[38;5;132;01m{\u001B[39;00margs_str\u001B[38;5;132;01m}\u001B[39;00m\u001B[38;5;130;01m\\n\u001B[39;00m\u001B[38;5;124m\"\u001B[39m)\n\u001B[0;32m    466\u001B[0m         e\u001B[38;5;241m.\u001B[39mpatch_message(msg)\n\u001B[1;32m--> 468\u001B[0m     \u001B[43merror_rewrite\u001B[49m\u001B[43m(\u001B[49m\u001B[43me\u001B[49m\u001B[43m,\u001B[49m\u001B[43m \u001B[49m\u001B[38;5;124;43m'\u001B[39;49m\u001B[38;5;124;43mtyping\u001B[39;49m\u001B[38;5;124;43m'\u001B[39;49m\u001B[43m)\u001B[49m\n\u001B[0;32m    469\u001B[0m \u001B[38;5;28;01mexcept\u001B[39;00m errors\u001B[38;5;241m.\u001B[39mUnsupportedError \u001B[38;5;28;01mas\u001B[39;00m e:\n\u001B[0;32m    470\u001B[0m     \u001B[38;5;66;03m# Something unsupported is present in the user code, add help info\u001B[39;00m\n\u001B[0;32m    471\u001B[0m     error_rewrite(e, \u001B[38;5;124m'\u001B[39m\u001B[38;5;124munsupported_error\u001B[39m\u001B[38;5;124m'\u001B[39m)\n",
      "File \u001B[1;32mF:\\Programs\\Python\\lib\\site-packages\\numba\\core\\dispatcher.py:409\u001B[0m, in \u001B[0;36m_DispatcherBase._compile_for_args.<locals>.error_rewrite\u001B[1;34m(e, issue_type)\u001B[0m\n\u001B[0;32m    407\u001B[0m     \u001B[38;5;28;01mraise\u001B[39;00m e\n\u001B[0;32m    408\u001B[0m \u001B[38;5;28;01melse\u001B[39;00m:\n\u001B[1;32m--> 409\u001B[0m     \u001B[38;5;28;01mraise\u001B[39;00m e\u001B[38;5;241m.\u001B[39mwith_traceback(\u001B[38;5;28;01mNone\u001B[39;00m)\n",
      "\u001B[1;31mTypingError\u001B[0m: Failed in nopython mode pipeline (step: nopython frontend)\n\u001B[1m\u001B[1mNo implementation of function Function(<built-in function setitem>) found for signature:\n \n >>> setitem(DictType[unicode_type,ListType[UniTuple(int32 x 2)]]<iv=None>, Literal[str](asdf), list(UniTuple(int64 x 2))<iv=None>)\n \nThere are 16 candidate implementations:\n\u001B[1m      - Of which 14 did not match due to:\n      Overload of function 'setitem': File: <numerous>: Line N/A.\n        With argument(s): '(DictType[unicode_type,ListType[UniTuple(int32 x 2)]]<iv=None>, unicode_type, list(UniTuple(int64 x 2))<iv=None>)':\u001B[0m\n\u001B[1m       No match.\u001B[0m\n\u001B[1m      - Of which 1 did not match due to:\n      Overload in function 'impl_setitem': File: numba\\typed\\dictobject.py: Line 674.\n        With argument(s): '(DictType[unicode_type,ListType[UniTuple(int32 x 2)]]<iv=None>, unicode_type, list(UniTuple(int64 x 2))<iv=None>)':\u001B[0m\n\u001B[1m       Rejected as the implementation raised a specific error:\n         NumbaNotImplementedError: Failed in nopython mode pipeline (step: native lowering)\n       \u001B[1m\u001B[1mCannot cast list(UniTuple(int64 x 2))<iv=None> to ListType[UniTuple(int32 x 2)]: %\"inserted.parent.1\" = insertvalue {i8*, i8*} %\"inserted.meminfo.2\", i8* %\"arg.value.1\", 1\u001B[0m\n       \u001B[0m\u001B[1mDuring: lowering \"castedval = call $12load_global.4(value, $16load_deref.6, func=$12load_global.4, args=[Var(value, dictobject.py:683), Var($16load_deref.6, dictobject.py:684)], kws=(), vararg=None, target=None)\" at F:\\Programs\\Python\\lib\\site-packages\\numba\\typed\\dictobject.py (684)\u001B[0m\u001B[0m\n  raised from F:\\Programs\\Python\\lib\\site-packages\\numba\\core\\base.py:715\n\u001B[1m      - Of which 1 did not match due to:\n      Overload in function 'impl_setitem': File: numba\\typed\\dictobject.py: Line 674.\n        With argument(s): '(DictType[unicode_type,ListType[UniTuple(int32 x 2)]]<iv=None>, Literal[str](asdf), list(UniTuple(int64 x 2))<iv=None>)':\u001B[0m\n\u001B[1m       Rejected as the implementation raised a specific error:\n         NumbaNotImplementedError: Failed in nopython mode pipeline (step: native lowering)\n       \u001B[1m\u001B[1mCannot cast list(UniTuple(int64 x 2))<iv=None> to ListType[UniTuple(int32 x 2)]: %\"inserted.parent\" = insertvalue {i8*, i8*} %\"inserted.meminfo.1\", i8* %\"arg.value.1\", 1\u001B[0m\n       \u001B[0m\u001B[1mDuring: lowering \"castedval = call $12load_global.4(value, $16load_deref.6, func=$12load_global.4, args=[Var(value, dictobject.py:683), Var($16load_deref.6, dictobject.py:684)], kws=(), vararg=None, target=None)\" at F:\\Programs\\Python\\lib\\site-packages\\numba\\typed\\dictobject.py (684)\u001B[0m\u001B[0m\n  raised from F:\\Programs\\Python\\lib\\site-packages\\numba\\core\\base.py:715\n\u001B[0m\n\u001B[0m\u001B[1mDuring: typing of staticsetitem at C:\\Users\\YeCanming\\AppData\\Local\\Temp\\ipykernel_11780\\3448497629.py (11)\u001B[0m\n\u001B[1m\nFile \"C:\\Users\\YeCanming\\AppData\\Local\\Temp\\ipykernel_11780\\3448497629.py\", line 11:\u001B[0m\n\u001B[1mdef test_hash_table(hash_table):\n\u001B[1m    hash_table['asdf'] = [(1,2)]\n\u001B[0m    \u001B[1m^\u001B[0m\u001B[0m\n"
     ]
    }
   ],
   "source": [
    "# types.UniTuple(types.int64,2)[:]\n",
    "types.ListType(types.UniTuple(types.int64,2))\n",
    "\n",
    "hash_table = Dict.empty(\n",
    "        key_type=types.unicode_type,\n",
    "        # value_type=types.List(types.UniTuple(types.int32,2))  # 表示行动的顺序\n",
    "        value_type=types.ListType(types.UniTuple(types.int32,2))\n",
    "    )\n",
    "@njit\n",
    "def test_hash_table(hash_table):\n",
    "    hash_table['asdf'] = [(1,2)]\n",
    "    print(hash_table['asdf'])\n",
    "test_hash_table(hash_table)"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "outputs": [
    {
     "ename": "TypeError",
     "evalue": "datetime_data() takes exactly 1 argument (0 given)",
     "output_type": "error",
     "traceback": [
      "\u001B[1;31m---------------------------------------------------------------------------\u001B[0m",
      "\u001B[1;31mTypeError\u001B[0m                                 Traceback (most recent call last)",
      "Input \u001B[1;32mIn [1]\u001B[0m, in \u001B[0;36m<cell line: 2>\u001B[1;34m()\u001B[0m\n\u001B[0;32m      1\u001B[0m \u001B[38;5;28;01mimport\u001B[39;00m \u001B[38;5;21;01mnumpy\u001B[39;00m \u001B[38;5;28;01mas\u001B[39;00m \u001B[38;5;21;01mnp\u001B[39;00m\n\u001B[1;32m----> 2\u001B[0m \u001B[43mnp\u001B[49m\u001B[38;5;241;43m.\u001B[39;49m\u001B[43mdatetime_data\u001B[49m\u001B[43m(\u001B[49m\u001B[43m)\u001B[49m\n",
      "\u001B[1;31mTypeError\u001B[0m: datetime_data() takes exactly 1 argument (0 given)"
     ]
    }
   ],
   "source": [
    "import numpy as np\n",
    "np.datetime_data()"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}